<?
$tables = mysql_list_tables($cfg['dbname']);
for ($i=0; $row=mysql_fetch_array($tables); $i++) {
	$repair = false;
	$SQL = "OPTIMIZE TABLE ".$row[0];
	mysql_query($SQL);
	$SQL = "ANALYZE TABLE ".$row[0];
	mysql_query($SQL);
	$SQL = "CHECK TABLE ".$row[0];
	$res = mysql_query($SQL);
	for ($i=0; $row=mysql_fetch_array($res); $i++) {
		if ($row['Msg_type'] != "status") {
			$repair = true;
		}
	}
	while ($repair) {
		$repair2 = false;
		$message = "Error found in table: ".$row[0].". Repairing.";
		webcp_log(1,0,"dbmaintenance",$message,0);
		$cronresults .= $message."\r\n";
		$SQL = "REPAIR TABLE ".$row[0];
		mysql_query($SQL);
		$SQL = "CHECK TABLE ".$row[0];
		$res = mysql_query($SQL);
		for ($i=0; $row=mysql_fetch_array($res); $i++) {
			if ($row['Msg_type'] != "status") {
				$repair2 = true;
			}
		}
		$repair = $repair2;
	}
}
if (!isset($cronresults)) { $cronresults = "All tables ok."; }
$result = 0;
?>
